/**
* 作者: lby
* 日期: 2024-11-14 08:52:43
* 备注: 用户不婚主义子嗣表
*/
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.base.AllParam;
import com.motu.monstercity.server.game.logic.ChildManager;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.redis.RedisTools;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;

public class UserChildAlone extends UserChildAloneModel {
	public UserChildAlone() {
		super();
	}

	public UserChildAlone(long userId, UserChildCls userChildCls) {
		super();
		putUserId(userId);
		putName(userChildCls.getName());
		putQuality(userChildCls.getQuality());
		putCareer(userChildCls.getCareer());
		putPartner(userChildCls.getPartner());
		putSecretary(userChildCls.getSecretary());
		putAppearance(userChildCls.getAppearance());
		putSex(userChildCls.getSex());
		putEarnAdd(userChildCls.getAddition());
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public JsonObject insert() {
		// 如果超过上限则会删除最早的那条
		long count = Future.await(RedisTools.getHashLen(getListKey()));
		if (count >= AllParam.CHILD_ALONE_SAVE_MAX) {
			String orderListKey = EntityManager.getOrderListKey(getListKey());
			String delRecord = Future.await(RedisTools.lpop(orderListKey));// 删除列表数据
			long id = Long.parseLong(delRecord);// dbid
			UserChildAlone userChildAlone = ChildManager.getUserChildAlone(getUserId(), id);
			if (userChildAlone != null) {
				userChildAlone.delete();
			}
		}
		return super.insert();
	}
}
